package chat

import (
	"sanguo/node/node_chat"
	ss_rpc "sanguo/protocol/ss/rpc"
	"sanguo/rpc/leaveChat"

	"github.com/golang/protobuf/proto"
)

type LeaveChat struct {
}

func (this *LeaveChat) OnCall(replyer *leaveChat.LeaveChatReplyer, arg *ss_rpc.LeaveChatReq) {

	node_chat.Debugln("OnCall LeaveChat", arg)

	chatMgr.PostTask(func() {

		role := chatMgr.Roles[arg.GetRoleID()]
		resp := &ss_rpc.LeaveChatResp{}
		resp.Ok = proto.Int32(1)
		if role == nil {
			replyer.Reply(resp)
			node_chat.Infoln("LeaveChat OK", arg.GetUserID())
			return
		}

		chatMgr.LeaveChat(role)
		node_chat.Infoln("LeaveChat OK", arg.GetUserID())

		replyer.Reply(resp)
	})
}

func init() {
	leaveChat.Register(&LeaveChat{})
}
